package io.github.talelin.latticy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.github.talelin.latticy.dto.machine.CreateOrUpdateMachineDTO;
import io.github.talelin.latticy.mapper.MachineMapper;
import io.github.talelin.latticy.model.MachineDO;
import io.github.talelin.latticy.service.MachineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author generator@TaleLin
 * @since 2021-05-20
 */
@Service
public class MachineServiceImpl extends ServiceImpl<MachineMapper, MachineDO> implements MachineService {

    @Autowired
    private MachineMapper machineMapper;

    @Override
    public boolean createMachine(CreateOrUpdateMachineDTO validator) {
        MachineDO machine = new MachineDO();
        machine.setMid(validator.getMid());
        machine.setMname(validator.getMname());
        machine.setLocation(validator.getLocation());
        machine.setRemark(validator.getRemark());
        return machineMapper.insert(machine) > 0;
    }

    @Override
    public boolean updateMachine(MachineDO machine, CreateOrUpdateMachineDTO validator) {
        machine.setMid(validator.getMid());
        machine.setMname(validator.getMname());
        machine.setLocation(validator.getLocation());
        machine.setRemark(validator.getRemark());
        return machineMapper.updateById(machine) > 0;
    }

    @Override
    public List<MachineDO> findAll() {
        List<MachineDO> machine = machineMapper.selectList(null);
        return machine;
    }

    @Override
    public boolean deleteById(Integer id) {
        return machineMapper.deleteById(id) > 0;
    }


}
